import ImgFileUpLoad from '@/components/ImgFileUpload/index.vue'
import moment from 'moment'
import { isHas } from '../../utils/validate'
import XmDatePicker from '@/components/XMC/XmDatePicker/index.vue'
import TakedMedicineList from '@/components/TakedMedicineList/index.vue'
import store from '@/store'
import { diffTimesToYear } from '@/utils/timeTools'
/**
 * 生成节点 前后描述文件
 * @param {*} title
 * @returns
 */
function $_span(title) {
  if (title) {
    return <span>{title}</span>
  }
  return null
}
/**
 * 解析节点
 * @param {*} cell 渲染节点对象
 * @returns 返回需要用到的参数
 */
function analysis(cell) {
  const { t, an, b } = cell
  const { v, w, bt, at, c, c1, d, ip } = b
  let [condition, btc, atc, items] = [[], null, null, dataDic['d1']]
  if (c) condition = c.split(',')
  if (bt) btc = $_span(bt)
  if (at) atc = $_span(at)
  if (d) {
    items = dataDic[d]
  }
  if (v)
    items = v.split(',').map((item) => {
      return { value: item, label: item }
    })
  return { t, an, b, items, w, btc, atc, condition, c1, d, ip, v }
}

/**
 *
 * @param {*} cell
 * @param {*} index
 * @param {*} form
 * @param {*} isC
 * @returns
 */
function $_i1(cell, index, form, isC, emit = () => {}) {
  const { an, w, condition, btc, atc, ip } = analysis(cell)
  // 设置默认值
  if (ip && checkFristInject(form[an])) {
    form[an] = ip
  }

  const st = { width: w ? w + 'px' : '240px' }
  const stc = { 'font-size': '18px' }
  const isNumber2 = condition.includes('decimal2')
  const isNumber = condition.includes('number')

  if (isC) {
    if (isNumber2) {
      return (
        <el-input
          style={st}
          v-model={form[an]}
          id={an + ''}
          onChange={(e) => emit(e)}
          v-number2
        ></el-input>
      )
    } else if (isNumber) {
      return (
        <el-input
          style={st}
          v-model={form[an]}
          id={an + ''}
          onChange={(e) => emit(e)}
          v-number
        ></el-input>
      )
    } else {
      return (
        <span
          id={an + ''}
          class="input1"
          class={condition.includes('nib') ? 'block' : 'inline-block'}
          style={stc}
        >
          {btc}
          <el-input
            style={st}
            v-model={form[an]}
            onChange={(e) => emit(e)}
          ></el-input>
          {atc}
        </span>
      )
    }
  } else {
    return (
      <span
        class="input1"
        id={an + ''}
        class={condition.includes('nib') ? 'block' : 'inline-block'}
        style={stc}
      >
        {btc}
        {isNumber ? (
          <el-input
            style={st}
            v-model={form[an]}
            disabled={cell.disabled}
            onChange={(e) => emit(e)}
            v-number
          ></el-input>
        ) : isNumber2 ? (
          <el-input
            style={st}
            v-model={form[an]}
            disabled={cell.disabled}
            onChange={(e) => emit(e)}
            v-number2
          ></el-input>
        ) : (
          <el-input
            style={st}
            v-model={form[an]}
            disabled={cell.disabled}
            onChange={(e) => emit(e)}
          ></el-input>
        )}

        {atc}
      </span>
    )
  }
}

function $_s1(cell, index, form, isC, emit = () => {}) {
  let { items, an, w, condition, btc, atc, d, ip } = analysis(cell)
  let multiple = false
  if (d === 'd2' || d === 'd3') {
    multiple = true
  }
  if (condition.includes('days')) {
    items = dataDic['days']
  } else if (condition.includes('weeks')) {
    items = dataDic['weeks']
  } else if (condition.includes('years')) {
    items = dataDic['months']
  } else if (condition.includes('months')) {
    items = dataDic['months']
  }
  const options = items.map((item, index) => {
    return (
      <el-option key={index} label={item.value} value={item.label}>
        <span style="float: left">{item.label}</span>
        {item.description ? (
          <span style="float: right; color: #8492a6; font-size: 13pxs">
            {item.description}
          </span>
        ) : null}
      </el-option>
    )
  })
  console.log(`start form[an] = ${form[an]} an = ${an}`)
  // 设置默认值
  if (ip && (form[an] === null || form[an] === undefined)) {
    form[an] = multiple ? ip.split(',') : ip
  }
  const st = { width: w ? w + 'px' : '60px' }
  console.log(`end form[an] = ${form[an]} an = ${an}`)
  function change(e, cell, form) {
    form[an] = e
    emit(e)
    console.log('form[an] =' + form[an])
  }
  if (isC) {
    return (
      <el-select
        multiple={multiple}
        clearable
        size="large"
        v-model={form[an]}
        style={st}
        disabled={cell.disabled}
        onChange={emit}
        // onChange={(e) => change(e, cell, form)}
        id={an + ''}
      >
        {options}
      </el-select>
    )
  }
  return (
    <span
      class="select1"
      id={an + ''}
      class={condition.includes('nib') ? 'block' : 'inline-block'}
    >
      {btc}
      <el-select
        multiple={multiple}
        clearable
        size="large"
        v-model={form[an]}
        style={st}
        disabled={cell.disabled}
        onChange={emit}
        // onChange={(e) => change(e, cell, form)}
      >
        {options}
      </el-select>
      {atc}
    </span>
  )
}

/**
 * 生成 radio 类型1
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns radio 类型1
 */
function $_r1(cell, index, form, isC, children, activeEmit, recordDate) {
  let { items, an, condition, btc, atc, c1, ip, d } = analysis(cell)

  // 设置默认值
  if (!ip && !form[an] && d) {
    form[an] = d
  }
  if (ip && checkFristInject(form[an])) {
    form[an] = ip
  }
  // 大于6岁后才显示
  if (
    condition.includes('age6') &&
    recordDate &&
    checkEmrYears(recordDate) < 6
  ) {
    return null
  }
  // 反选
  const checkClick = async (event, value, cell, form) => {
    if (cell.disabled || d) return
    if (!event.preventDefault()) {
      if (checkRadioToReverseSel(form[an], value)) {
        form[an] = null
      } else {
        form[an] = value
      }
      $_radioChange(event, cell, form)
      // 掉用回调
      activeEmit && activeEmit(an)
    }
  }
  const radios = items.map((item, index) => {
    return (
      <el-radio
        size="large"
        key={index}
        onClick={($event) => checkClick($event, item.value, cell, form)}
        label={item.label}
        value={item.value}
      ></el-radio>
    )
  })

  return (
    <span
      class={condition.includes('nib') ? 'block' : 'inline-block'}
      id={an + ''}
    >
      {btc}
      <el-radio-group
        v-model={form[an]}
        onChange={(e) => $_radioChange(e, cell, form)}
        disabled={cell.disabled}
      >
        {radios}
      </el-radio-group>
      {atc}
      {$_is(an, c1, form) ? children : ''}
    </span>
  )
}

/**
 * 生成 checkbox-group/checkbox 类型1
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns checkbox-group/checkbox 类型1
 */
function $_c1(cell, index, form, isC, children, activeEmit) {
  let { items, an, condition, btc, atc, ip } = analysis(cell)
  const checkboxs = items.map((item) => {
    return (
      <el-checkbox
        size="large"
        label={item.label}
        value={item.value}
      ></el-checkbox>
    )
  })
  // 设置默认
  if (!form[an]) ip ? (form[an] = ip.split(',')) : (form[an] = [])
  function $_checkboxGroupChange(value) {
    form[an] = value
    activeEmit && activeEmit({ attr: an, value })
  }

  return (
    <span
      class={condition.includes('nib') ? 'block' : 'inline-block'}
      id={an + ''}
    >
      {btc}
      <el-checkbox-group
        v-model={form[an]}
        onChange={$_checkboxGroupChange}
        disabled={cell.disabled}
      >
        {checkboxs}
      </el-checkbox-group>
      {atc}
      {form[an] && Array.isArray(form[an]) && form[an].length > 0
        ? children
        : null}
    </span>
  )
}
/**
 * 生成 img 类型1
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns checkbox-group/checkbox 类型1
 */
function $_img1(cell, index, form) {
  let { an, condition, btc, atc, ip } = analysis(cell)
  // 设置默认值
  if (ip && !form[an]) {
    form[an] = ip
  }
  return (
    <span
      class={condition.includes('nib') ? 'image1' : 'inline-block'}
      id={an + ''}
    >
      {btc}
      <ImgFileUpLoad
        ref="imgFileUploadRef"
        id="imgFileUpload"
        v-model={form[an]}
        disabled={cell.disabled}
        fileAccept=".png,.jpg,.jpeg,.gif,application/pdf"
      ></ImgFileUpLoad>
      {atc}
    </span>
  )
}

/**
 * 生成 medicineList 类型1
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns jsx
 */
function $_medicineList(cell, index, form) {
  let { an, condition, btc, atc, ip } = analysis(cell)
  // 设置默认值
  if (ip && !form[an]) {
    form[an] = ip
  }
  return (
    <div id={an + ''}>
      {btc}
      <TakedMedicineList
        ref="takeMedicineListRef"
        v-model={form[an]}
        disabled={cell.disabled}
      ></TakedMedicineList>
      {atc}
    </div>
  )
}

/**
 * 生成 t1 类型1
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns checkbox-group/checkbox 类型1
 */
function $_t1(cell) {
  let { items, condition } = analysis(cell)
  return (
    <span
      style="line-height: 18px;"
      class={condition.includes('nib') ? 'block' : 'inline-block'}
    >
      {items[0].label}
    </span>
  )
}

/**
 * 生成 t1 类型1
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns checkbox-group/checkbox 类型1
 */
function $_t2(cell, index, form, clickEvent) {
  let { items, condition, ip, an } = analysis(cell)
  if (ip && !form[an]) {
    form[an] = ip
  }
  return (
    <div
      style="line-height: 18px; font-size:16px; padding:5px"
      id={an + ''}
      class={condition.includes('nib') ? 'block' : 'inline-block'}
    >
      <el-button
        disabled={cell.disabled}
        size="small"
        type="primary"
        onClick={() => clickEvent(items[0].label, form[an])}
      >
        {items[0].label}
      </el-button>
      <span class="t2-tips-class">{form[an]}</span>
    </div>
  )
}

/**
 * 生成 radio 类型2
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns radio2 类型2
 */
function $_r2(cell, index, form, isC, children, $_returnCom) {
  let { items, an, condition, btc, atc, ip } = analysis(cell)
  // 设置默认值
  if (ip && checkFristInject(form[an])) {
    form[an] = ip
  }

  const checkClick = async (event, value) => {
    if (cell.disabled) return
    if (!event.preventDefault()) {
      if (checkRadioToReverseSel(form[an], value)) {
        form[an] = null
      } else {
        form[an] = value
      }
      $_radioChange(event, cell, form)
    }
  }
  const options = items.map((item, index) => {
    return (
      //
      <span id={an + ''}>
        <el-radio
          size="large"
          key={index}
          label={item.label}
          onClick={($event) => checkClick($event, item.value, cell, form)}
          value={item.value}
          disabled={cell.disabled}
        >
          {item.label}
        </el-radio>
        {form[an] && form[an].includes(item.label) && cell.children[index]
          ? $_returnCom(
              { ...cell.children[index], disabled: cell.disabled },
              index,
              isC
            )
          : null}
      </span>
    )
  })
  return (
    <span
      class={condition.includes('nib') ? 'block' : 'inline-block'}
      id={an + ''}
    >
      {btc}
      <el-radio-group v-model={form[an]} disabled={cell.disabled}>
        {options}
      </el-radio-group>
      {atc}
    </span>
  )
}

/**
 * 生成 radio 类型2
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns radio2 类型2
 */
function $_c2(cell, index, form, isC, children, $_returnCom) {
  let { items, an, condition, btc, atc, ip } = analysis(cell);
  // 设置默认值
  if (!form[an]) {
    ip ? (form[an] = ip.split(',')) : (form[an] = [])
  }
  const options = items.map((item, index) => {
        return (
      <el-checkbox
        size="large"
        key={index}
        label={item.label}
        value={item.value}
      >
        <div class="normal-content">
          {item.label}
        </div>
        <div class='children-content'>
          {form[an] && form[an].includes(item.label) && cell.children[index]
            ? $_returnCom(cell.children[index])
            : null}
        </div>
      </el-checkbox>
    )
  })
  // 初始化checkbox group要用的属性
  // if (!form[an]) form[an] = []
  return (
    <span
      class={condition.includes('nib') ? 'block' : 'inline-block'}
      id={an + ''}
    >
      {btc}
      <el-checkbox-group v-model={form[an]} disabled={cell.disabled}>
        {options}
      </el-checkbox-group>
      {atc}
    </span>
  )
}

function $_c3(cell, index, form) {
  let { items, an, condition, btc, atc, ip } = analysis(cell)
  // 设置默认值
  if (!form[an]) {
    ip ? (form[an] = ip.split(',')) : (form[an] = [])
  }
  // c = ['rall-咳嗽变异性哮喘(CVA)', 'rpair-学龄前反复喘息:学龄前反复喘息？']
  let allKey = null
  let key1 = null
  let key2 = null
  if (form[an].length !== 0 && condition) {
    condition.filter((item) => {
      let tmp = item.split('-')
      if (Array.isArray(tmp) && tmp.length > 1) {
        if (tmp[0] === 'rall') allKey = tmp[1]
        if (tmp[0] === 'rpair') {
          let tmp1 = tmp[1].split(':')
          key1 = tmp1[0]
          key2 = tmp1[1]
        }
      }
    })
    if (allKey && form[an].includes(allKey) && form[an].length > 1) {
      // 如果选了cva 取消所有
      form[an] = [allKey]
    }
    if (
      form[an].length >= 2 &&
      form[an].includes(key1) &&
      form[an].includes(key2)
    ) {
      let index1 = null
      let index2 = null
      form[an].forEach((e, index) => {
        if (e === key1) index1 = index
        if (e === key2) index2 = index
      })
      if (index1 !== null && index2 !== null) {
        if (index1 > index2) form[an].splice(index2, 1)
        if (index2 > index1) form[an].splice(index1, 1)
      }
    }
  }
  const options = items.map((item, index) => {
    if (cell.children && cell.children[index]) {
      form[cell.children[index].an] = cell.children[index].b.ip
    }
    let content = null
    if (cell.children && cell.children[index]) {
      content = form[cell.children[index].an]

      if (content) {
        const tmp = content.split('\n')
        content = tmp.map((item) => {
          const { tip, notTip, haveTip, closeTag } = splitTipsWithArray(item)
          return (
            <div>
              <span>{tip}</span>
              <span style="color: #FF3737">{notTip}</span>
              <span style="color: #33CA90">{haveTip}</span>
              <span>{closeTag}</span>
            </div>
          )
        })
      }
    }
    const tooltipf = function (content, label) {
      return (
        <el-tooltip
          effect="light"
          placement="bottom-start"
          disabled={!content}
          v-slots={{
            content: () => content,
          }}
        >
          <div>
            <span>{label}</span>
          </div>
        </el-tooltip>
      )
    }

    // 处理rall的情况
    let disabled = false
    if (form[an].length === 1 && form[an].includes('咳嗽变异性哮喘(CVA)')) {
      disabled = true
      if (item.value === '咳嗽变异性哮喘(CVA)') disabled = false
    }
    return (
      <el-checkbox
        size="large"
        key={index}
        label={item.label}
        value={item.value}
        disabled={disabled}
      >
        {content ? tooltipf(content, item.label) : <span>{item.label}</span>}
      </el-checkbox>
    )
  })
  return (
    <span
      class={condition.includes('nib') ? 'block' : 'inline-block'}
      id={an + ''}
    >
      {btc}
      <el-checkbox-group
        v-model={form[an]}
        disabled={cell.disabled || condition.includes('dall')}
        class={condition.includes('dall') ? 'disabledClass' : ''}
      >
        {options}
      </el-checkbox-group>
      {atc}
    </span>
  )
}

/**
 * 生成 $_timeSelect 类型1
 * @param {*} cell 节点数据
 * @param {*} index 父节点编号
 * @param {*} form 表单数据
 * @param {*} isC 是子模块
 * @param {*} children 渲染的子节点
 * @returns checkbox-group/checkbox 类型1
 */
function $_timeSelect(cell, index, form) {
  let { items, an, w, condition, btc, atc, d, ip } = analysis(cell)
  // 设置默认值
  console.log('ip =' + ip)
  if (ip && checkFristInject(form[an])) {
    form[an] = ip ? moment(ip).format('YYYY-MM-DD HH:mm:ss') : null
  }
  return (
    <span
      class="select2"
      id={an + ''}
      class={condition.includes('nib') ? 'block' : 'inline-block'}
    >
      {btc}
      {}
      <XmDatePicker
        disabled={cell.disabled}
        type="date"
        disabledDateT="before"
        v-model={form[an]}
        label="选择复诊时间"
        prop="fillingTime"
        style="width: 180px"
      ></XmDatePicker>
      {atc}
    </span>
  )
}

/**
 * 修改checkboxGroup值
 * @param {*} el 改变的数据
 * @param {*} id form 属性name
 * @param {*} form 表单数据
 */
// function $_checkboxGroupChange(el, id, form) {
//   form[id] = el
// }

/**
 * 修改checkbox值
 * @param {*} el 改变的数据
 * @param {*} cell 渲染的节点 属性name
 * @param {*} form 表单数据
 */
function $_checkboxChange(el, cell, form) {
  console.log('el =' + el)
  console.log('cell =' + cell)
  if (!form[cell.an] || form[cell.an].length === 0) {
    clearAttr(cell.children, form)
  }
}
/**
 * 用于单选框清理
 * @param {Object} e
 * @param {Object} cell
 * @param {Object} form
 */
function $_radioChange(e, cell, form) {
  if (!$_is(cell.an, cell.b.c1, form)) {
    clearAttr(cell.children, form)
  }
}

/**
 * 用于选择非条件后清除子控件的值
 * @param {Object} children
 * @param {Object} form
 */
function clearAttr(children, form) {
  console.log('clearAttr')
  if (children && Array.isArray(children)) {
    children.map((cell) => {
      if (!cell) return
      if (Array.isArray(form[cell.an])) {
        form[cell.an] = []
      } else {
        form[cell.an] = ''
      }
      if (Array.isArray(cell.children) && cell.children.length > 0) {
        cell.children.map((item) => {
          clearAttr(item, form)
        })
      }
    })
  }
}
/**
 *
 * @param {String} an
 * @param {String} c1 后端设置等同true类型
 * @returns Boolen
 */
function $_is(an, c1, form) {
  if (!form[an]) return
  const str = form[an]
  if (
    str === '是' ||
    str === '有' ||
    str === '1' ||
    str === true ||
    (c1 && str === c1)
  ) {
    return true
  }
  return false
}

/**
 * 判断参数是否第一次赋值 目前只有$_i1用 因为input删除完 是'' 会照成误判
 * @param {*} val
 */
function checkFristInject(val) {
  // 第一次val为undefined，为null或者具体数值类型则
  if (typeof val === 'undefined') {
    return true
  } else {
    return false
  }
}

function splitTipsWithArray(tips) {
  const notIndex = tips.indexOf('不具备')
  let tip = null
  let notTip = null
  let haveTip = null
  let closeTag = null
  if (notIndex !== -1) {
    tip = tips.substr(0, notIndex)
    notTip = '不具备'
    closeTag = ')'
  } else {
    const haveIndex = tips.indexOf('具备')
    if (haveIndex !== -1) {
      tip = tips.substr(0, haveIndex)
      haveTip = '具备'
      closeTag = ')'
    }
  }
  return { tip, notTip, haveTip, closeTag }
}
/**
 * 判断两次值是否一样，全都存在且一致 返回true
 * @param {*} pre 旧数据
 * @param {*} next 新数据
 * @return
 */
function checkRadioToReverseSel(pre, next) {
  if (!isHas(pre) || !isHas(next)) {
    return false
  } else if (pre === next) {
    return true
  }
  return false
}
export default {
  $_i1,
  $_s1,
  $_r1,
  $_c1,
  $_img1,
  $_medicineList,
  $_t1,
  $_t2,
  $_r2,
  $_c2,
  $_c3,
  $_timeSelect,
  // $_radio1,
}

const dataDic = {
  days: [
    { value: 1, label: 1 },
    { value: 2, label: 2 },
    { value: 3, label: 3 },
    { value: 4, label: 4 },
    { value: 5, label: 5 },
    { value: 6, label: 6 },
    { value: 7, label: 7 },
    { value: 8, label: 8 },
    { value: 9, label: 9 },
    { value: 10, label: 10 },
    { value: 11, label: 11 },
    { value: 12, label: 12 },
    { value: 13, label: 13 },
    { value: 14, label: 14 },
    { value: 15, label: 15 },
    { value: 16, label: 16 },
    { value: 17, label: 17 },
    { value: 18, label: 18 },
    { value: 19, label: 19 },
    { value: 20, label: 20 },
    { value: 21, label: 21 },
    { value: 22, label: 22 },
    { value: 23, label: 23 },
    { value: 24, label: 24 },
    { value: 25, label: 25 },
    { value: 26, label: 26 },
    { value: 27, label: 27 },
    { value: 28, label: 28 },
    { value: 29, label: 29 },
    { value: 30, label: 30 },
  ],
  months: [
    { value: 1, label: 1 },
    { value: 2, label: 2 },
    { value: 3, label: 3 },
    { value: 4, label: 4 },
    { value: 5, label: 5 },
    { value: 6, label: 6 },
    { value: 7, label: 7 },
    { value: 8, label: 8 },
    { value: 9, label: 9 },
    { value: 10, label: 10 },
    { value: 11, label: 11 },
  ],
  weeks: [
    { value: 1, label: 1 },
    { value: 2, label: 2 },
    { value: 3, label: 3 },
  ],
  d2: [
    {
      value: '短效β2受体激动剂（SABA）',
      label: '短效β2受体激动剂（SABA）',
      description: '特布他林、沙丁胺醇等',
    },
    {
      value: '口服型短效β2受体激动剂',
      label: '口服型短效β2受体激动剂',
      description: '盐酸丙卡特罗口服溶液等',
    },
    {
      value: '长效口服β2受体激动剂',
      label: '长效口服β2受体激动剂',
      description: '沙美特罗、福莫特罗等',
    },
    {
      value: '吸入性糖皮质激素',
      label: '吸入性糖皮质激素',
      description: '丙酸倍氯米松、布地奈德、氟替卡松等',
    },
    {
      value: '吸入抗胆碱能药物',
      label: '吸入抗胆碱能药物',
      description: '异丙托溴铵、噻托溴铵、格隆溴铵等',
    },
    {
      value: '全身用糖皮质激素',
      label: '全身用糖皮质激素',
      description: '泼尼松，地塞米松，氢化可的松',
    },
    { value: '硫酸镁', label: '硫酸镁' },
    { value: '茶碱', label: '茶碱' },
  ],
  d3: [
    {
      value: '吸入糖皮质激素',
      label: '吸入糖皮质激素',
      description: '丙酸倍氯米松、布地奈德、氟替卡松等',
    },
    {
      value: '白三烯调节剂',
      label: '白三烯调节剂',
      description: '普鲁斯特、孟鲁司特、扎鲁斯特等',
    },
    {
      value: '吸入糖皮质激素+长效吸入型b2受体激动剂(LABA)联合制剂',
      label: '吸入糖皮质激素+长效吸入型b2受体激动剂(LABA)联合制剂',
      description: '福莫特罗、沙美特罗、班布特罗等',
    },
    {
      value: '长效口服β2受体激动剂',
      label: '长效口服β2受体激动剂',
      description: '沙美特罗、福莫特罗等',
    },
    { value: '口服缓释（或控释）茶碱', label: '口服缓释（或控释）茶碱' },
    { value: '抗IgE抗体', label: '抗IgE抗体', description: '奥马珠单抗' },
    {
      value: '抗组胺药物',
      label: '抗组胺药物',
      description: '左旋西替利嗪、西替利嗪、氯雷他定等',
    },
    // { value: '吸入短效β2受体激动剂(SABA)', label: '吸入短效β2受体激动剂(SABA)' },
    // { value: '口服短效β2受体激动剂(SABA)', label: '口服短效β2受体激动剂(SABA)' },
    // { value: '吸入抗胆碱能药物', label: '吸入抗胆碱能药物' },
    // { value: '静脉用硫酸镁', label: '静脉用硫酸镁' },
  ],
}

function checkEmrYears(recordDate) {
  const birthday = store.getters.patientInfo.birthday
  const recordBirthday = store.getters.emrRecordBirthday

  // 时间以备份的时间为准
  const years = diffTimesToYear(recordDate, recordBirthday || birthday)
  return years
}
